package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.base.model.Organization;
import com.yunfeisoft.business.dao.inter.HospitalConsultDao;
import com.yunfeisoft.business.model.HospitalConsult;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * ClassName: HospitalConsultDaoImpl
 * Description: 入院咨询Dao实现
 * Author: Jackie liu
 * Date: 2020-01-13
 */
@Repository
public class HospitalConsultDaoImpl extends BaseDaoImpl<HospitalConsult, String> implements HospitalConsultDao {

    @Override
    public Page<HospitalConsult> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
            wb.andEquals("hc.orgId", params.get("orgId"));
            wb.andFullLike("hc.consultName", params.get("consultName"));
        }

        SelectBuilder builder = getSelectBuilder("hc");
        builder.column("org.name as orgName")
                .leftJoin(Organization.class).alias("org").on("hc.orgId = org.id").build();

        return queryPage(builder.getSql(), wb);
    }
}